//
//  RecomView.m
//  BosidengIphone
//
//  Created by  on 12-1-17.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "RecomView.h"
#import "MainViewController.h"
#import "MyShowDetailViewController.h"

@implementation RecomView
@synthesize mData;
@synthesize mainViewController;

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        imageView = [[SyncImageView alloc] init];
        imageView.frame = self.bounds;
        [self addSubview:imageView];
        [imageView release];
        
        button = [UIButton buttonWithType:UIButtonTypeCustom];
        button.frame = self.bounds;
        [self addSubview:button];
        [button addTarget:self action:@selector(imageClick:) forControlEvents:UIControlEventTouchUpInside];
    }
    return self;
}

- (void)imageClick:(id)sender {
    if (mainViewController && mData) {
        MyShowDetailViewController *detailView = [[MyShowDetailViewController alloc] initWithNibName:@"MyShowDetailViewController" bundle:nil];
        detailView.data = mData;
        [(MainViewController *)mainViewController pushViewController:detailView];
        [detailView release];
    }
}

- (void)dealloc {
    self.mainViewController = nil;
    [mData release];
    [super dealloc];
}

- (void)loadData:(MyShowData *)data andRequestQueue:(NSOperationQueue *)queue viewController:(id)viewController {
    //NSLog(@"loadData self=%@", self);
    self.mainViewController = viewController;
    self.mData = data;
    NSString *imageUrl = data.smallImage;
    [imageView loadImage:imageUrl andRequestQueue:queue];
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

@end
